﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace System.Runtime.Serialization.Advanced
{
  public class BinaryGraphSerializer
  {
    private Stream _output;

    public BinaryGraphSerializer(Stream output)
    {
      _output = output;
    }

    public void Serialize(DataGraph graph)
    {
      //Write the header.
      BinaryWriter writer = new BinaryWriter(_output);
      writer.Write("AS/Binary//");

      writer.Write(graph.Data1.Keys.Count);
      //Write out the data types
      foreach(var type in graph.Data1.Keys)
        WriteDataContract(graph.DataDescriptions[type]);

      foreach(var type in graph.Data1.Keys)
      {
        writer.Write(graph.Data1[type].Count);
        foreach (IGraphable obj in graph.Data1[type])
          obj.GetFiel ds()
      }
    }

    private void WriteDataContract(DataContract dataDescription)
    {
      throw new NotImplementedException();
    }


    public void Serialize(IGraphable obj)
    {
      DataGraph graph = new DataGraph();
      graph.Add(obj);
      Serialize(graph);
    }

    public void Serialize(IEnumerable<IGraphable> objs)
    {
      DataGraph graph = new DataGraph();
      graph.Add(objs);
      Serialize(graph);
    }
  }
}
